import React, { PropTypes } from 'react';
import xFetch, { get, post } from '../util/xFetch';
import { Router, Route, IndexRoute, IndexRedirect, Redirect } from 'dva/router';
import NotFound from '../components/notFound';
import App from '../components/'; // 引入菜单内容
import MyHome from '../components/my-home'; //个人中心
import editMyHome from '../components/my-home/edit'; //编辑

import Login from '../login/'; //登录
import adminLogin from '../adminLogin/'; //管理员快递员登录
import kLogin from '../kLogin/'; //快递员登录

import Register from '../register/'; //注册
import Userindex from '../userindex/'; //用户首页
import UserindexUpdate from '../userindex/updatelocation.jsx'; //用户首页更改位置
import UserindexSign from '../userindex/usign.jsx'; //用户首页签收
import UserindexnoComment from '../userindex/unocomment.jsx'; //用户首页评价
import UserindexComment from '../userindex/ucomment.jsx'; //用户首页评价
import UserindexVideoList from '../userindex/uvideolist.jsx'; //用户首页视频清单
import UserindexSearchNumber from '../userindex/usearchnumber.jsx'; //用户首页搜索快递单号
import UserindexMy from '../userindex/umy.jsx'; //用户首页个人中心



import Repassword from '../repassword/'; //找回密码
import Kindex from '../components/my-kindex'; //快递员首页
import Kindexmy from '../components/my-kindex/my'; //快递员首页
import KindexmyEdit from '../components/my-kindex/edit'; //快递员编辑
import KindexVideolist from '../components/my-kindex/videolist'; //快递员视频清单


import carlocation from '../components/my-kindex/location'; //快递员位置

import Mindex from '../components/my-mindex'; //管理员首页
import Maidetail from '../components/my-mindex/aidetail'; //ai详情
import MPersonal from '../components/my-mindex/personal'; //人员列表
import MPersonalSearch from '../components/my-mindex/personalsearch'; //人员搜索
import MRegulations from '../components/my-mindex/regulations'; //违章
import MRegulationsDetail from '../components/my-mindex/regulationsDetail'; //违章详情
import MRegulationsSearch from '../components/my-mindex/regulationssearch'; //违章搜索
import MStaticsManage from '../components/my-mindex/staticsManage'; //统计分析


import Mmessage from '../components/my-mindex/message'; //管理员消息
import Mmap from '../components/my-mindex/map'; //管理员消息
import Mmaptravel from '../components/my-mindex/maptravel'; //轨迹
import MMy from '../components/my-mindex/my'; //管理员我的




import MyInfo from '../components/my-info'; //个人资料


function requireAuth(nextState, replaceState) {
  const token = localStorage.getItem('token');
  if (!token) {
    replaceState({ nextPathname: nextState.location.pathname }, '/');
  }
}

function Routes({ history }) {
  return (
    <Router history={history}>
      <Route path="/login" component={Login} />
      <Route path="/adminlogin" component={adminLogin} />
      <Route path="/klogin" component={kLogin} />

      <Route path="/Register" component={Register} />
      <Route path="/uindex" component={Userindex} />
      <Route path="/ulocation" component={UserindexUpdate} />
      <Route path="/usign" component={UserindexSign} />
      <Route path="/ucomment" component={UserindexComment} />
      <Route path="/unocomment" component={UserindexnoComment} />
      <Route path="/uvideolist" component={UserindexVideoList} />
      <Route path="/usearchnumber" component={UserindexSearchNumber} />
      <Route path="/umy" component={UserindexMy} />


      <Route path="/Repassword" component={Repassword} />
      <Redirect from="/" to="/login" />
      <Route onEnter={requireAuth} path="/:id/app/" component={App}>
        <Route path="/:id/app/MyHome" component={MyHome} />
        <Route path="/:id/app/editMy" component={editMyHome} />
        <Route path="/:id/app/kindex" component={Kindex} />
        <Route path="/:id/app/kmy" component={Kindexmy} />
        <Route path="/:id/app/kmyedit" component={KindexmyEdit} />
        <Route path="/:id/app/carlocation" component={carlocation} />
        <Route path="/:id/app/kvideolist" component={KindexVideolist} />


        <Route path="/:id/app/mindex" component={Mindex} />
        <Route path="/:id/app/maidetail" component={Maidetail} />
        <Route path="/:id/app/mpersonal" component={MPersonal} />
        <Route path="/:id/app/mpersonalsearch" component={MPersonalSearch} />
        <Route path="/:id/app/mregulations" component={MRegulations} />
        <Route path="/:id/app/mregulationsdetail" component={MRegulationsDetail} />
        <Route path="/:id/app/mregulationssearch" component={MRegulationsSearch} />
        <Route path="/:id/app/mstaticsManage" component={MStaticsManage} />
        

        <Route path="/:id/app/mmy" component={MMy} />
        <Route path="/:id/app/mmessage" component={Mmessage} />
        <Route path="/:id/app/mmap" component={Mmap} />
        <Route path="/:id/app/mmaptravel" component={Mmaptravel} />
        <Route path="/:id/app/MyInfo" component={MyInfo} />
        <IndexRoute component={MyHome} />
      </Route>
      <Route path="*" component={NotFound} />
    </Router>
  );
}
Routes.propTypes = {
  history: PropTypes.any // eslint-disable-line
};
export default Routes;
